import { defineStore } from "pinia";

export const userMenu = defineStore("userMenu", {
    state: () => {
        return {
            menu: [],
            incode: -1,
            user: {
                // username: "李四",
                // password: "cccc",
                // id: 2,
                // username: "暴龙战士",
                // password: "aaaa",
                // id: '2302'
                password: "",
                id: ''
            },
            menuBeifen: JSON.parse(localStorage.getItem("menuBeifen")),
        }
    },
    getters: {

    },
    actions: {
        // 添加用户菜单数据
        addUserMenu(payload) {
            let a = payload;
            for (let i = 0; i < a.length; i++) {
                this.menu.push(a[i]);
            }
            // 将菜单数据存储本地
            localStorage.setItem("menuBeifen", JSON.stringify(this.menu));
        },
        // 清楚用户菜单数据
        resetUserMenu(payload) {
            this.menu = [];
        },
        // 备份菜单数据回复
        BeifenMenu() {
            this.menu = this.menuBeifen;
        },
        ResetUser() {
            for (let key in this.user) {
                this.user[key] = ""
            }
        }
    },
    persist: {
        enabled: true
    }
})